package com.ruoyi.web.controller.rest;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.CacheUtils;
import com.ruoyi.system.domain.WebRecycleType;
import com.ruoyi.system.service.IWebRecycleTypeService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;
import java.util.Map;

/**
 * 微信公众号菜单 信息操作处理
 * 
 * @author liupan
 * @date 2019-03-25
 */
//@Api(tags = "回收分类管理")
//@RestController
//@RequestMapping("/rest/recycle/type")
public class _RecycleTypeController extends BaseController {
	@Autowired
	private IWebRecycleTypeService iWebRecycleTypeService;


	@ApiOperation(value = "获取回收一级分类",notes = "")
	@GetMapping()
	public AjaxResult getRecycle() {
		List<Map<String,Object>> news = null;
		Object cacheObj = CacheUtils.get(Constants.RECYCLE_TYPE_KEY, Constants.RECYCLE_TYPE_KEY+":parent");
		if(cacheObj != null){
			news = (List<Map<String,Object>>)cacheObj;
		}else{
			news = iWebRecycleTypeService.listMaps(new QueryWrapper<WebRecycleType>()
//				.eq("deleted","N") //没有这个标识，注销掉
					.eq("status",0)
					.eq("parent_id",0)
					.select("id","name","price","unit","image").orderByAsc("order_num"));
			if(CollectionUtils.isNotEmpty(news)){
				CacheUtils.put(Constants.RECYCLE_TYPE_KEY, Constants.RECYCLE_TYPE_KEY+":parent", news);
			}
		}

		return AjaxResult.success(news);
	}

	@ApiOperation(value = "获取一级分类的详细分类",notes = "")
	@GetMapping("detail/{id}")
	public AjaxResult getRecycleDetail(@PathVariable("id") Integer id) {
		List<Map<String,Object>> news = iWebRecycleTypeService.listMaps(new QueryWrapper<WebRecycleType>()
//				.eq("deleted","N")  ////没有这个标识，注销掉
				.eq("status",0)
				.eq("parent_id",id)
				.select("id","name","price","unit","comment").orderByAsc("order_num"));

		return AjaxResult.success(news);
	}

}
